<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@page import ="keydot.commons.utils.*" %>

<meta http-equiv="Content-Type" content="text/html"> 
<html>
	<body>
		<%@page language="java" import="java.net.*,java.io.*"%>
		<%
			request.setCharacterEncoding("UTF-8");
			String whereSql=request.getParameter("whereSql");
			String sql = "select id 编号, ygzh 用户警号 ,ygxm 用户名称, ygzw 用户职务 from xt_ygb where 1=1 "+whereSql ;
			String path = "";
	 		JspExport export=new JspExport();
			path = export.export("用户信息.xls",sql);
			String filenamedownload = path;
			
			response.reset();//可以加也可以不加
			response.setContentType("application/x-download");

			String filedisplay ="用户信息.xls";
			filedisplay = URLEncoder.encode(filedisplay, "UTF-8");
			response.addHeader("Content-Disposition", "attachment;filename="
					+ filedisplay);

			OutputStream outp = null;
			FileInputStream in = null;
			try {
				outp = response.getOutputStream();
				
				in = new FileInputStream(filenamedownload);

				byte[] b = new byte[1024];
				int i = 0;

				while ((i = in.read(b)) > 0) {
					outp.write(b, 0, i);
				}
				outp.flush();
				//此处是处理getoutputstream()方法与inputstream并存时必报的异常
				out.clear(); 
				out = pageContext.pushBody(); 
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (in != null) {
					in.close();
					in = null;
				}
				if (outp != null) {
					outp.close();
					outp = null;
				}
			File f = new File(filenamedownload); //path:E:/tomcat/...  

			try {

				f.delete();
				f.deleteOnExit();
				//session.setAttribute("exemsql", "");
			} catch (Exception e) {
			e.printStackTrace();
			}
			}
		%>
	</body>
</html>
